<%--
  Created by IntelliJ IDEA.
  User: tm-hu
  Date: 2018/9/21
  Time: 11:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@ include file="/common/baseMeta.jsp" %>

    <script type="text/javascript" src="/static/js/common.js"></script>
    <title>职业暴露</title>
    <script type="text/javascript">

        var uid="${sysStaffEntity.uid}";
        var lname="${sysStaffEntity.lname}"; //登录名
        var uname="${sysStaffEntity.uname}"; //用户名
        var role_name=""; //用户角色

        $(function () {

            var now = new Date()
            var nowDay = now.getDate(); //当前日
            var nowMonth = now.getMonth() + 1; //当前月
            var lastMonth = now.getMonth();
            var nowYear = now.getYear(); //当前年
            nowYear += (nowYear < 2000) ? 1900 : 0;

            if (nowMonth < 10) {
                nowMonth = "0" + nowMonth;
            }
            if (nowDay < 10) {
                nowDay = "0" + nowDay;
            }

            if (lastMonth < 10) {
                lastMonth = "0" + lastMonth;
            }

            $("#sdate").val(nowYear + '-' + lastMonth + '-' + nowDay);
            $("#edate").val(nowYear + '-' +nowMonth  + '-' + nowDay);

            $("#Maingrid").height(300);
            $("#Contentgrid").height(350);
            initMaingrid();
            initContentgrid();
            //主表信息
            BandMainGrid();
        })
        function BandMainGrid() {
            var postdata = {
                p_dm: "Thz_zybl_get",
                sdate: $("#sdate").val() == "" ? '1987-01-01' : $("#sdate").val(),
                edate: $("#edate").val() == "" ? '2090-03-01' : $("#edate").val()
            };
            //从API获取数据，并绑定
            $.getJSON("/commapiV2", postdata, function (data) {
                if (data.success) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#Maingrid').datagrid('loadData', griddata);
                    $("#Maingrid").datagrid("selectRow", 0);
                    var row = $('#Maingrid').datagrid('getSelected');
                    BandContentGrid(row.ID);
                }
            });
        }
        //从表信息
        function BandContentGrid(id)
        {
            $.getJSON("/commapiV2", {
                p_dm: "THZ_ZYBL_JYJGZZ_get",
                mid:id
            }, function (data) {
                if (data.success) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#Contentgrid').datagrid('loadData', griddata);
                }
            }, true);
        }
        function initMaingrid() {
            $('#Maingrid').datagrid({
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                pagination: true,//启用分页
                fitColumns: true,
                sortable: true, //启用排序列
                collapsible: true,
                idField: 'ID',
                pageSize: 50,
                pageList: [50, 100, 150],
                columns: [
                    [
                        {field: 'HNAME', title: '姓名', width: '120px', align: 'center'},
                        {field: 'HSEX', title: '性别', width: '50px', align: 'center'},
                        {field: 'HAGE', title: '年龄', width: '50px', align: 'center'},
                        {field: 'ksname', title: '科室', width: '120px', align: 'center'},
                        {field: 'zy', title: '职业', width: '80px', align: 'center'},
                        {field: 'gzsj', title: '工作时间', width: '250px', align: 'center'},
                        {field: 'HEXPOSUREMOTION', title: '暴露时从事何种医疗活动', width: '250px', align: 'center'},
                        {field: 'blsj', title: '暴露时间', width: '250px', align: 'center'},
                        {field: 'bldd', title: '暴露地点', width: '250px', align: 'center'},
                        {field: 'ID', title: 'ID', hidden: true}
                    ]
                ],
                onClickRow: function (index, field, value) {
                    var row = $('#Maingrid').datagrid('getSelected');
                    BandContentGrid(row.ID);
                }
            }).datagrid('clientPaging');
        }
        function initContentgrid() {
            $('#Contentgrid').datagrid({
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                pagination: false,//启用分页
                fitColumns: true,
                sortable: true, //启用排序列
                collapsible: true,
                idField: 'MID',
                columns: [
                    [
                        {field: 'AZ_BD', title: '艾滋病毒初筛试验', width: '120px', align: 'center'},
                        {field: 'YG_BDEKT', title: '乙肝病毒e抗体', width: '120px', align: 'center'},
                        {field: 'YG_BDEKY', title: '乙肝病毒e抗原', width: '90px', align: 'center'},
                        {field: 'YG_BMKTDL', title: '乙肝表面抗体定量', width: '120px', align: 'center'},
                        {field: 'YG_BMKY', title: '乙肝表面抗原', width: '100px', align: 'center'},
                        {field: 'YG_HXKT', title: '乙肝核心抗体', width: '90px', align: 'center'},
                        {field: 'BG_BDIGG', title: '丙肝病毒IgG', width: '120px', align: 'center',editor: { type: 'text'}},
                        {field: 'MD_LXTKT', title: '梅毒螺旋体抗体', width: '80px', align: 'center'},
                        {field: 'CSSJ', title: '测试时间', width: '80px', align: 'center'},
                        {field: 'JCZLF', title: '检查治疗费', width: '80px', align: 'center'},
                        {field: 'YF', title: '药费', width: '80px', align: 'center'},
                        {field: 'LX', title: '类型', width: '80px', align: 'center'},
                        {field: 'ID', title: 'ID', hidden: true},
                        {field: 'MID', title: 'MID', hidden: true}
                    ]
                ],
                onClickCell: function (index, field, value) {
                    var row = $('#Contentgrid').datagrid('getSelected');
                    $("#Contentgrid").datagrid('selectRow', index);
                    $("#Contentgrid").datagrid('beginEdit', index);
                }
            })
        }
        //修改检测信息
        function EditZybl() {
            var row = $('#Maingrid').datagrid('getSelected');
            if(row.zt=='已发送'){
                alert("数据已发送不能编辑，如需修改请作废重新填写并发送！");
                return;
            }
            var url = "/FormApi?mobanId=51376a9a-10d2-4739-910c-3a6dc9e909e9&dataId="+row.ID;
            layeropen(850, 600, "数据编辑", url);
        }
        function AddZybl()
        {
            var url = "/FormApi?mobanId=51376a9a-10d2-4739-910c-3a6dc9e909e9&dataId";
            layeropen(850, 600, "添加", url);
        }
    </script>
</head>
<body>
<div class="navheader form-inline" style="height:40px;margin-bottom: 0px;">
    <div class=" form-group">
        <label for="CYRQStart" style="padding:5px 10px 0 20px;">暴露日期1</label>
        <input type="text" class="form-control Wdate" style="width:100px;" name="sdate" id="sdate"
               placeholder=""
               value="${CYRQStart}"
               onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })"/>
        <label for="CYRQEnd" style="padding:5px 10px 0 10px;">至</label>
        <input type="text" class="form-control Wdate" style="width:100px;" name="edate" id="edate"
               placeholder=""
               value="${CYRQEnd}"
               onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })"/>

        <button type="button" class="btn btn-success bi-btn-search" onclick="BandMainGrid()">
            <span class="glyphicon glyphicon glyphicon-search"></span>
        </button>
        <div class="btn-group-right">
            <div class="btn-group" role="group">
                <button type="button" class="btn btn-default bi-btn-width90" id="tj" onclick="AddZybl()">添加</button>
                <button type="button" class="btn btn-default bi-btn-width90" id="xg" onclick="EditZybl()">修改</button>
            </div>
        </div>
    </div>
</div>
<div style="width:100%;float:left;display:inline-block;padding-top:10px;">
    <table id="Maingrid" class="datagrid" style="width:100%"></table>
</div>
<div style="width:100%;float:left;display:inline-block;padding-top:10px;">
    <table id="Contentgrid" class="datagrid" style="width:100%"></table>
</div>
</body>
</html>
